﻿using System;

namespace Test30.Core
{
    public static class SingleExtensions
    {
        public static float Normalize(this float value, float min, float max)
        {
            if (Math.Abs(max -min)<1e-8) throw new ArgumentOutOfRangeException($"min和max不能相等.");
            return (value - min) / (max - min);
        }

        public static float Remap(this float value, float min, float max, float outMin, float outMax)
        {
            if (Math.Abs(max - min) < 1e-8) throw new ArgumentOutOfRangeException($"min和max不能相等.");
            return (value.Normalize(min, max) * (outMax - outMin)) + outMin;
        }

        public static void Swap<T>(ref T left, ref T right)
        {
            T temp = left;
            left = right;
            right = temp;
        }

    }
}
